package com.shark.demo;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName DeadLock
 * @Description TODO
 * @Author 东北彭于晏
 * @Date 2024/9/30  17:32
 * @Version 1.0
 **/
public class DeadLock {
    public static void main(String[] args) {
        Object LockA = new Object();
        Object LockB = new Object();

        new Thread(() -> {
            synchronized (LockA){
                try {
                    TimeUnit.SECONDS.sleep(1);
                    synchronized (LockB){
                        System.out.println(Thread.currentThread().getName());
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
        },"A" ).start();



        new Thread(() -> {
            synchronized (LockB){
                try {
                    TimeUnit.SECONDS.sleep(1);
                    synchronized (LockA){
                        System.out.println(Thread.currentThread().getName());
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"B" ).start();
    }
}